/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/compare-version-numbers
   @Language: C++
   @Datetime: 19-11-21 19:43
   */

class Solution {
	string split(string &s){
		int i=0, j=0;
		for(; i<s.length() && s[i]=='0'; ++i);
		for(j=i; j<s.length() && s[j]!='.'; ++j);
		string t=s.substr(i,j-i);
		s=s.substr(j==s.length()?j:j+1);
		return t.length()?t:"0";
	}
public:
	int compareVersion(string version1, string version2) {
		int diff=0;
		for(; !diff && (version1.length() || version2.length());){
			string v1=split(version1), v2=split(version2);
			if(v1.length()==v2.length()) diff=v1.compare(v2);
			else return v1.length()>v2.length()?1:-1;
		}
		return diff>0?1:(diff<0?-1:0);
	}
};
